<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:p="http://primefaces.org/ui">
    
    
 	<ui:composition template="/pages/template.xhtml">
	    <ui:define name="conteudo">
	    	<f:view beforePhase="#{authorizationListener.anuncianteAndAdminPhase}" >
	    	
	    		<h:form id="form_addcategoria">
	    			<h1>Adicionar categoria</h1>
	    			
	    			<p:messages id="messages" />
	    			
	    			<h:inputHidden value="#{categoriaBean.categoria.idCategoria}" id="id_categoria"/>
	    			
	    			<h:panelGrid columns="2">
	    				<h:outputLabel value="Categoria Principal:" for="master_categoria"/>
			    		<p:selectOneMenu value="#{categoriaBean.master}" id="master_categoria" disabled="#{categoriaBean.categoria.idCategoria != 0}" required="true" requiredMessage="Tipo master é obrigatório.">
			    			<f:selectItem itemLabel="Não" itemValue="#{false}" />
			    			<f:selectItem itemLabel="Sim" itemValue="#{true}" />
			    			<f:ajax render="painel" execute="@this" event="change"/>
			    		</p:selectOneMenu>
	    			</h:panelGrid>
	    			
			    	<h:panelGrid columns="2" id="painel">
			    		<h:outputLabel value="Categoria pai" id="label_categoria_pai" for="categoria_pai" rendered="#{!categoriaBean.master}" />
			    		<p:selectOneMenu value="#{categoriaBean.categoria.categoriaPai}" id="categoria_pai" rendered="#{!categoriaBean.master}">
			    				<f:selectItems value="#{categoriaBean.listaTodasCategorias}"  var="c" itemLabel="#{c.nome}" itemValue="#{c.idCategoria}" />
			    		</p:selectOneMenu>

			    		<h:outputLabel value="Nome categoria" for="nome_categoria"/>
			    		<h:inputText value="#{categoriaBean.categoria.nome }" id="nome_categoria" required="true" requiredMessage="Nome é obrigatório."/>
			    		
			    	</h:panelGrid>
			    	<br/><br/>
			    	
			    	<h:panelGroup>
			    		<h:commandButton value="Voltar" styleClass="botao" action="tabelaCategorias.xhtml" immediate="true"/>
			    		<h:commandButton value="Concluir" styleClass="botao" action="#{categoriaBean.adicionar}" />
			    	</h:panelGroup>
		    	
				</h:form>
			</f:view>
	    </ui:define>
  	</ui:composition>
  	
</html>